package com.emep.changzhi.analyse.service.datamonitor.minute;

import com.emep.changzhi.analyse.entity.datamonitor.minute.DataMinuteVehicleEmissions;
import com.emep.changzhi.analyse.repository.datamonitor.minute.DataMinuteVehicleRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;
import java.util.Map;

/**
 * @author yangj
 * @version V1.0
 * @Description: 机动车尾气监测_分钟数据表业务层
 * @date 2018/2/27  16:12
 */
@Slf4j
@Service
public class DataMinuteVehicleService {

    @Resource
    private DataMinuteVehicleRepository dataMinuteVehicleRepository;

    /**
     *
     * 新增
     *
     * @param payload
     * @return
     * @throws Exception
     */
    public DataMinuteVehicleEmissions save(Map<String, Object> payload) {
        DataMinuteVehicleEmissions dataMinuteVehicleEmissions = null;
        try {
            DataMinuteVehicleEmissions dataMinuteVehicleEmissions1 = (DataMinuteVehicleEmissions) MapUtils.convertMap(DataMinuteVehicleEmissions.class,payload);
            dataMinuteVehicleEmissions = dataMinuteVehicleRepository.save(dataMinuteVehicleEmissions1);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataMinuteVehicleEmissions;
    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 10:11
     * @version V1.0
     */
    public List<DataMinuteVehicleEmissions> findDataMinuteVehicleEmissionsByHome(Integer pageSize){
        List<DataMinuteVehicleEmissions> dataMinuteVehicleEmissionss = null;
        try {
            dataMinuteVehicleEmissionss = dataMinuteVehicleRepository.dataMinuteVehicleHome(pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataMinuteVehicleEmissionss;

    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 10:18
     * @version V1.0
     */

    public List<DataMinuteVehicleEmissions> findDataMinuteVehicleEmissionsByFlip(String id,Integer pageSize) {
        List<DataMinuteVehicleEmissions> dataMinuteVehicleEmissionss = null;
        try {
            dataMinuteVehicleEmissionss = dataMinuteVehicleRepository.dataMinuteVehicleFlip(id,pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataMinuteVehicleEmissionss;
    }

}
